﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.SqlClient;
using System.Linq;
using System.Web;

namespace Project_Udrinkwater
{
    public class InsertTime
    {
        string Connection = ConfigurationManager.ConnectionStrings["DB_Udrink"].ConnectionString;
        public static object GetDataValue(object value)
        {
            if (value == null)
            {
                return DBNull.Value;
            }

            return value;
        }
        public void Insertss(Data DataTime)
        {
            string sqltext = @"insert into TB_Time_Cards 
                                   ( [Employee_ID]
                                    ,[Check_in])
                                   values (@Empoyee_ID,@Check_IN)";
            SqlCommand sqlcomm = new SqlCommand();
            SqlConnection sqlconn = new SqlConnection(Connection);
            sqlcomm.Connection = sqlconn;
            sqlcomm.CommandType = System.Data.CommandType.Text;
            sqlcomm.CommandText = sqltext;
            sqlcomm.Parameters.AddWithValue("@Empoyee_ID", GetDataValue(DataTime.Empoyee_ID));
            sqlcomm.Parameters.AddWithValue("@Check_IN", GetDataValue(DataTime.Checkin));
           
            try
            {
                sqlcomm.Connection.Open();
                sqlcomm.ExecuteNonQuery();
            }
            catch (Exception)
            {

                sqlcomm.Connection.Close();
                sqlcomm.Connection.Dispose();
            }
            sqlcomm.Connection.Close();
            sqlcomm.Connection.Dispose();

        }
        public void Insert_DataSalaryDetial(Data Data)
        {
            string sqltext = @"INSERT INTO [TB_Salary]
                                ([Employee_ID]
                                ,[Salary_StartMonth]
                                ,[Salary_EndMonth]
                                ,[OT]
                                ,[Reduce_Absence]
                                ,[Reduce_Withdraw]
                                ,[Reduce_Other]
                                ,[Commission])
                                values (@Empoyee_ID,@Salary_StartMonth,@Salary_EndMonth,@OT,@Reduce_Absence,@Reduce_Withdraw,@Reduce_Other,@Commission)";
            SqlCommand sqlcomm = new SqlCommand();
            SqlConnection sqlconn = new SqlConnection(Connection);
            sqlcomm.Connection = sqlconn;
            sqlcomm.CommandType = System.Data.CommandType.Text;
            sqlcomm.CommandText = sqltext;
            sqlcomm.Parameters.AddWithValue("@Empoyee_ID", GetDataValue(Data.Empoyee_ID));
            sqlcomm.Parameters.AddWithValue("@Salary_StartMonth", GetDataValue(Data.Start_Salary));
            sqlcomm.Parameters.AddWithValue("@Salary_EndMonth", GetDataValue(Data.End_Salary));
            sqlcomm.Parameters.AddWithValue("@OT", GetDataValue(Data.Overtime));
            sqlcomm.Parameters.AddWithValue("@Reduce_Absence", GetDataValue(Data.Reduce_Absence));
            sqlcomm.Parameters.AddWithValue("@Reduce_Withdraw", GetDataValue(Data.Reduce_Withdraw));
            sqlcomm.Parameters.AddWithValue("@Reduce_Other", GetDataValue(Data.Other));
            sqlcomm.Parameters.AddWithValue("@Commission", GetDataValue(Data.Commission));

            try
            {
                sqlcomm.Connection.Open();
                sqlcomm.ExecuteNonQuery();
            }
            catch (Exception)
            {

                sqlcomm.Connection.Close();
                sqlcomm.Connection.Dispose();
            }
            sqlcomm.Connection.Close();
            sqlcomm.Connection.Dispose();

        }
        public void InsertOvertime(Data DataTime)
        {
            string sqltext = @"insert into TB_EmployeeOT 
                                   ([Employee_ID]
                                    ,[Start_OT])
                                   values (@Empoyee_ID,@Start_OT)";
            SqlCommand sqlcomm = new SqlCommand();
            SqlConnection sqlconn = new SqlConnection(Connection);
            sqlcomm.Connection = sqlconn;
            sqlcomm.CommandType = System.Data.CommandType.Text;
            sqlcomm.CommandText = sqltext;
            sqlcomm.Parameters.AddWithValue("@Empoyee_ID", GetDataValue(DataTime.Empoyee_ID));
            sqlcomm.Parameters.AddWithValue("@Start_OT", GetDataValue(DataTime.Start_OT));

            try
            {
                sqlcomm.Connection.Open();
                sqlcomm.ExecuteNonQuery();
            }
            catch (Exception)
            {

                sqlcomm.Connection.Close();
                sqlcomm.Connection.Dispose();
            }
            sqlcomm.Connection.Close();
            sqlcomm.Connection.Dispose();

        }
        public void Inserts_Order(Data DataTime)
        {
            string sqltext = @"insert into [TB_Order] 
                                   ([Order_Date_Time]
                                    ,[Deadlines_Date]
                                    ,[Employee_ID]
                                    ,[Customer_ID])
                                   values (@Deadline,@Order,@Empoyee_ID,@Customer)";
            SqlCommand sqlcomm = new SqlCommand();
            SqlConnection sqlconn = new SqlConnection(Connection);
            sqlcomm.Connection = sqlconn;
            sqlcomm.CommandType = System.Data.CommandType.Text;
            sqlcomm.CommandText = sqltext;
            sqlcomm.Parameters.AddWithValue("@Deadline", GetDataValue(DataTime.Empoyee_ID));
            sqlcomm.Parameters.AddWithValue("@Order", GetDataValue(DataTime.Checkin));
            sqlcomm.Parameters.AddWithValue("@Empoyee_ID", GetDataValue(DataTime.Checkin));
            sqlcomm.Parameters.AddWithValue("@Customer", GetDataValue(DataTime.Checkin));

            try
            {
                sqlcomm.Connection.Open();
                sqlcomm.ExecuteNonQuery();
            }
            catch (Exception)
            {

                sqlcomm.Connection.Close();
                sqlcomm.Connection.Dispose();
            }
            sqlcomm.Connection.Close();
            sqlcomm.Connection.Dispose();

        }
    }
}